package simple

// https://leetcode-cn.com/problems/toeplitz-matrix/
// 托普利茨矩阵
// 算法: 直接遍历
func IsToeplitzMatrix(matrix [][]int) bool {
	lenX, lenY := len(matrix), len(matrix[0])
	// 向右移动和向左移动，分别遍历一次
	x, y := 0, 0
	for ; y < lenY; y++ {
		currentX, currentY := x, y
		currentValue := matrix[x][y]
		for currentX < lenX && currentY < lenY {
			if matrix[currentX][currentY] != currentValue {
				return false
			}
			currentX++
			currentY++
		}
	}

	x, y = 1, 0
	for ; x < lenX; x++ {
		currentX, currentY := x, y
		currentValue := matrix[x][y]
		for currentX < lenX && currentY < lenY {
			if matrix[currentX][currentY] != currentValue {
				return false
			}
			currentX++
			currentY++
		}
	}
	return true
}
